﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QualityEvaluatingTools.model;
using System.Xml.Linq;
using QualityEvaluatingTools.helper;

namespace QualityEvaluatingTools.manager
{
    public static class CalManager
    {
        /// <summary>
        /// 获取压力测试的分数
        /// </summary>
        /// <param name="evaluation"></param>
        /// <param name="xDocument"></param>
        /// <returns></returns>
        public static EvaluationItem GetPressureTestScore(Evaluation evaluation, IEnumerable<XElement> xDocument)
        {
            //定义压力测评
            EvaluationItem evaluationItem = new EvaluationItem();

            //这里将会使用枚举，暂时这么干
            evaluationItem.Name = "压力测评";

            //得分
            int socre = 0;

            //计算得分
            foreach (var item in evaluation.StuAnswerList)
            {
                socre += XmlHelper.GetStuSelectScore(item, xDocument);
            }
            evaluationItem.Score = socre;

            return evaluationItem;
        }

        // <summary>
        /// 获取心理承受能力测试的分数
        /// </summary>
        /// <param name="evaluation"></param>
        /// <param name="xDocument"></param>
        /// <returns></returns>
        public static EvaluationItem GetPsychologicalBearTestScore(Evaluation evaluation, IEnumerable<XElement> xDocument)
        {
            //定义心理承受测评
            EvaluationItem evaluationItem = new EvaluationItem();

            //这里将会使用枚举，暂时这么干
            evaluationItem.Name = "心理承受能力测评";

            //得分
            int socre = 0;

            //计算得分
            foreach (var item in evaluation.StuAnswerList)
            {
                socre += XmlHelper.GetStuSelectScore(item, xDocument);
            }
            evaluationItem.Score = socre;


            return evaluationItem;
        }

        // <summary>
        /// 获取自主性测试的分数
        /// </summary>
        /// <param name="evaluation"></param>
        /// <param name="xDocument"></param>
        /// <returns></returns>
        public static EvaluationItem GetAutonomyTestScore(Evaluation evaluation, IEnumerable<XElement> xDocument)
        {
            //定义自主性测评
            EvaluationItem evaluationItem = new EvaluationItem();

            //这里将会使用枚举，暂时这么干
            evaluationItem.Name = "自主性测评";

            //得分
            int socre = 0;

            //计算得分
            foreach (var item in evaluation.StuAnswerList)
            {
                socre += XmlHelper.GetStuSelectScore(item, xDocument);
            }
            evaluationItem.Score = socre;


            return evaluationItem;
        }

        // <summary>
        /// 获取交际能力测试的分数
        /// </summary>
        /// <param name="evaluation"></param>
        /// <param name="xDocument"></param>
        /// <returns></returns>
        public static EvaluationItem GetCommunicationAbilityScore(Evaluation evaluation, IEnumerable<XElement> xDocument)
        {
            //定义交际能力测评
            EvaluationItem evaluationItem = new EvaluationItem();

            //这里将会使用枚举，暂时这么干
            evaluationItem.Name = "交际能力测评";

            //得分
            int socre = 0;

            //计算得分
            foreach (var item in evaluation.StuAnswerList)
            {
                socre += XmlHelper.GetStuSelectScore(item, xDocument);
            }
            evaluationItem.Score = socre;

            return evaluationItem;
        }

        // <summary>
        /// 获取职业性格测试的结果
        /// </summary>
        /// <param name="evaluation"></param>
        /// <param name="xDocument"></param>
        /// <returns></returns>
        public static EvaluationItem GetOccupationalCharacterTestResult(Evaluation evaluation, IEnumerable<XElement> xDocument)
        {
            //定义职业性格测评
            EvaluationItem evaluationItem = new EvaluationItem();

            evaluationItem.Name = "职业性格测评";

            //结果
            string result = "";

            // 测试数据
            string testResult = "";

            //计算得分
            foreach (var item in evaluation.StuAnswerList)
            {
                testResult += XmlHelper.GetStuOccupationalCharacterTestResult(item, xDocument);
            }

            int ECount = testResult.Count(c => c == 'E');
            int ICount = testResult.Count(c => c == 'I');

            int NCount = testResult.Count(c => c == 'N');
            int SCount = testResult.Count(c => c == 'S');

            int FCount = testResult.Count(c => c == 'F');
            int TCount = testResult.Count(c => c == 'T');

            int JCount = testResult.Count(c => c == 'J');
            int PCount = testResult.Count(c => c == 'P');

            if (ECount > ICount)
            {
                result += "E";
            }
            else
            {
                result += "I";
            }

            if (NCount > SCount)
            {
                result += "N";
            }
            else
            {
                result += "S";
            }

            if (FCount > TCount)
            {
                result += "F";
            }
            else
            {
                result += "T";
            }

            if (JCount > PCount)
            {
                result += "J";
            }
            else
            {
                result += "P";
            }

            evaluationItem.result = result;

            return evaluationItem;
        }
    }
}
